﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class editEmployeeRecordsModule : Form
    {
        percentDeduction form1;
        selection parent;
        public editEmployeeRecordsModule(selection parent)
        {
            this.parent = parent;
            InitializeComponent();
            informationPayingBasisDropDownList.SelectedIndex = 0;
            informationPositionDropDownList.SelectedIndex = 0;
            informationStatusDropDownList.SelectedIndex = 0;
        }

        private void informationEdit_Click(object sender, EventArgs e)
        {
            if (informationEdit.Text == "Edit") 
            {
                informationFirstNameTextBox.Enabled = true;
                informationLastNameTextBox.Enabled = true;
                informationSalaryTextBox.Enabled = true;
                informationWorkHoursTextBox.Enabled = true;
                informationPayingBasisDropDownList.Enabled = true;
                informationPositionDropDownList.Enabled = true;
                informationStatusDropDownList.Enabled = true;
          /*      informationContractEndMonthDropDownList.Enabled = true;
                informationContractEndDateDropDownList.Enabled = true;
                informationContractEndYearDropDownList.Enabled = true;*/
                informationContractEnd.Enabled = true;
                informationSssTextBox.Enabled = true;
                informationPhilhealthTextBox.Enabled = true;
                informationDebtTextBox.Enabled = true;
                informationBonusesTextBox.Enabled = true;
                informationCancel.Visible = true;
                informationEdit.Text = "Save";
            }
            else
            {
                informationFirstNameTextBox.Enabled = false;
                informationLastNameTextBox.Enabled = false;
                informationSalaryTextBox.Enabled = false;
                informationWorkHoursTextBox.Enabled = false;
                informationPayingBasisDropDownList.Enabled = false;
                informationPositionDropDownList.Enabled = false;
                informationStatusDropDownList.Enabled = false;
    /*            informationContractEndMonthDropDownList.Enabled = false;
                informationContractEndDateDropDownList.Enabled = false;
                informationContractEndYearDropDownList.Enabled = false;*/
                informationContractEnd.Enabled = false;
                informationSssTextBox.Enabled = false;
                informationPhilhealthTextBox.Enabled = false;
                informationDebtTextBox.Enabled = false;
                informationBonusesTextBox.Enabled = false;
                informationCancel.Visible = false;
                informationEdit.Text = "Edit";
            }
        }

        private void attendanceEditButton_Click(object sender, EventArgs e)
        {
            if (attendanceEditButton.Text == "Edit")
            {
                attendanceLateTextBox.Enabled = true;
                attendanceAbsencesTextBox.Enabled = true;
                attendanceCancelButton.Visible = true;
                attendanceEditButton.Text = "Save";
            }
            else
            {
                attendanceLateTextBox.Enabled = false;
                attendanceAbsencesTextBox.Enabled = false;
                attendanceCancelButton.Visible = false;
                attendanceEditButton.Text = "Edit";
            }

        }

        private void back_Click(object sender, EventArgs e)
        {
            parent.Show();
            this.Hide();
        }

        private void salaryChargeAdd_Click(object sender, EventArgs e)
        {
            addEditChargeModule form = new addEditChargeModule();
            form.Text = "Add Salary Charge";
            form.ShowDialog();
        }

        private void tipChargeAdd_Click(object sender, EventArgs e)
        {
            addEditChargeModule form1 = new addEditChargeModule();
            form1.Text = "Add Tip Charge";
            form1.ShowDialog();
        }

        public editEmployeeRecordsModule getEditEmployeeRecordsModule()
        {
            return this;
        }

        private void tipChargeEdit_Click(object sender, EventArgs e)
        {
            addEditChargeModule form = new addEditChargeModule();
            form.Text = "Edit Tip Charge";
            form.ShowDialog();
        }

        private void salaryChargeEdit_Click(object sender, EventArgs e)
        {
            addEditChargeModule form = new addEditChargeModule();
            form.Text = "Edit Salary Charge";            
            form.ShowDialog();
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            DialogResult result = MessageBox.Show("Are you sure you want to exit the program?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.No)
                e.Cancel = true;
            else
                Environment.Exit(1);
        }

        private void add_Click(object sender, EventArgs e)
        {
            addEmployee form = new addEmployee(editEmployeeList);
            form.ShowDialog();
        }

        private void Information_Click(object sender, EventArgs e)
        {
            
        }

        private void delete_Click(object sender, EventArgs e)
        {
            try
            {
                int index = editEmployeeList.SelectedIndex;
                List<string> employeeList = new List<string>();
                foreach (String strCol in editEmployeeList.Items)
                {
                    employeeList.Add(strCol);
                }
                employeeList.RemoveAt(index);
                DialogResult result = MessageBox.Show("Are you sure you want to delete the selected employee?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result != DialogResult.Yes)
                {
                    //do nothing
                }
                else
                {
                    editEmployeeList.DataSource = employeeList;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("No selected employee to be deleted", "Alert",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

        private void informationCancel_Click(object sender, EventArgs e)
        {
            informationFirstNameTextBox.Enabled = false;
            informationLastNameTextBox.Enabled = false;
            informationSalaryTextBox.Enabled = false;
            informationWorkHoursTextBox.Enabled = false;
            informationPayingBasisDropDownList.Enabled = false;
            informationPositionDropDownList.Enabled = false;
            informationStatusDropDownList.Enabled = false;
            /*            informationContractEndMonthDropDownList.Enabled = false;
                        informationContractEndDateDropDownList.Enabled = false;
                        informationContractEndYearDropDownList.Enabled = false;*/
            informationContractEnd.Enabled = false;
            informationSssTextBox.Enabled = false;
            informationPhilhealthTextBox.Enabled = false;
            informationDebtTextBox.Enabled = false;
            informationBonusesTextBox.Enabled = false;
            informationCancel.Visible = false;
            informationEdit.Text = "Edit";
        }

        private void attendanceCancelButton_Click(object sender, EventArgs e)
        {
            attendanceLateTextBox.Enabled = false;
            attendanceAbsencesTextBox.Enabled = false;
            attendanceCancelButton.Visible = false;
            attendanceEditButton.Text = "Edit";
        }

        private void editEmployeePercentDeductionButton_Click(object sender, EventArgs e)
        {
            if (form1 == null) 
            {
                form1 = new percentDeduction(editEmployeeList);
            }

            form1.ShowDialog();
        }

        private void tipChargeDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the selected tip charge?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result != DialogResult.Yes)
            {
            }
            else
            {
            }
        }

        private void salaryChargeDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the selected salary charge?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result != DialogResult.Yes)
            {
            }
            else
            {
            }
        }
    }
}
